#include <iostream>
#include "../include/App.h"
#include "../include/ParametersParser.h"
#include "../include/PatternFinder.h"
#include "../include/MmapFinder.h"
#include <map>
#include <fstream>
#include <vector>

App* App::m_instance = NULL;

App::App()
{
    //ctor
}

App::~App() {
    delete m_instance;
}

App* App::getInstance() {
    if (m_instance == NULL) {
        m_instance = new App();
    }
    return m_instance;
}

/**
 *
 * Metoda odpalająca parser, szukacza, wyświetlacza wyników
 *
 */
void App::run(int _argc, char** _argv) {
    ParametersParser* parametersParser = new ParametersParser(_argc, _argv);
    if (parametersParser->containFlag("-aio")) {
        std::cout << "aio" << std::endl;
        PatternFinder<AsynchronousFinder> syncPatternFinder(parametersParser->getParametersList(),
                                                            parametersParser->getFilesList(), parametersParser->getPattern());
    } else if (parametersParser->containFlag("-mmap"))
        PatternFinder<MmapFinder> syncPatternFinder(parametersParser->getParametersList(), parametersParser->getFilesList(), parametersParser->getPattern());
    else
        PatternFinder<SynchronousFinder> syncPatternFinder(parametersParser->getParametersList(), parametersParser->getFilesList(), parametersParser->getPattern());
    delete parametersParser;
}
